﻿using System;
using 浏览器客户端.Models.Interfaces;

namespace 浏览器客户端.Models.Model
{
    public class Patient
    {
        /// <summary>
        /// HisId
        /// </summary>
        public string HisCode { get; set; }

        /// <summary>
        /// 就诊卡号
        /// </summary>
        public string CardNo { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 余额
        /// </summary>
        public decimal Balance { get; set; }

        /// <summary>
        /// 身份证UID
        /// </summary>
        public string Uid { get; set; }

        /// <summary>
        /// 电话号码
        /// </summary>
        public string Phone { get; set; }

        /// <summary>
        /// 地址
        /// </summary>
        public string Address { get; set; }

        /// <summary>
        /// 出生日期
        /// </summary>
        public DateTime BirthTime
        {
            get
            {
                try
                {
                    var y = int.Parse(IdCardNo.Substring(6, 4));
                    var m = int.Parse(IdCardNo.Substring(10, 2));
                    var d = int.Parse(IdCardNo.Substring(12, 2));
                    return new DateTime(y, m, d);
                }
                catch (Exception)
                {
                    return DateTime.Now;
                }
            }
        }

        /// <summary>
        /// 性别
        /// </summary>
        public SexEnum Sex
        {
            get
            {
                try
                {
                    if (int.Parse(IdCardNo.Substring(16, 1)) % 2 == 0)
                    {
                        return SexEnum.女;
                    }
                    else
                    {
                        return SexEnum.男;
                    }
                }
                catch (Exception)
                {
                    return SexEnum.未知;
                }
            }
        }

        /// <summary>
        /// 年龄
        /// </summary>
        public int Age
        {
            get
            {
                var days = (int)(DateTime.Now - BirthTime).TotalDays;
                return days / 365;
            }
        }

        /// <summary>
        /// 民族
        /// </summary>
        public string MinZu { get; set; }

        /// <summary>
        /// 身份证号码
        /// </summary>
        public string IdCardNo { get; set; }

        /// <summary>
        /// 社保卡号码
        /// </summary>
        public string IcCardNo { get; set; }

        /// <summary>
        /// 卡片类型
        /// </summary>
        public CardTypeEnum CardType { get; set; }
    }
}